﻿using System.Collections.Generic;
using System.IO;
using data.contracts.messages;
using ebcpatterns;
using fileadapter;
using generator;
using modelbuilder;
using projectfile;

namespace PreBuildStep
{
    internal class Program
    {
        private static void Main(string[] args) {
            var ebcDateinamenErmitteln = new EbcDateinamenErmitteln();
            var defaultNamespace = new DefaultNamespace();
            var modelBuilder = new ModelBuilder();
            var generator = new Generator();
            var fileadapter = new FileAdapter();
            var join1 = new Join<IEnumerable<string>, string, BuildBoardsMessage>((filenames, @namespace) => new BuildBoardsMessage(filenames, @namespace));
            var join2 = new Join<string, string, SaveMessage>((content, filename) => new SaveMessage(filename, content));

            ebcDateinamenErmitteln.Out_Result += join1.Input1;
            defaultNamespace.Out_Result += join1.Input2;
            join1.Output += modelBuilder.In_Process;

            modelBuilder.Out_Result += generator.In_Process;

            generator.Out_Result += join2.Input1;
            join2.Output += fileadapter.In_Process;

            ebcDateinamenErmitteln.In_Process(args[0]);
            defaultNamespace.In_Process(args[0]);
            
            var outputPath = Path.GetDirectoryName(args[0]);
            var outputFilename = Path.Combine(outputPath, "generated.ebc.cs");
            join2.Input2(outputFilename);
        }
    }
}